<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <transition name="el-zoom-in-center">
        <div v-show="showLogo" class="transition-box1">
          <span class="logo iconfont icon-gaotie"></span>
        </div>
      </transition>
      <transition name="el-collapse-transition">
        <div v-show="showName" class="transition-box2">
          <span>HROWS后台管理系统</span>
        </div>
      </transition>
      <el-button class="logout" size="mini" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse? '64px':'250px'">
        <div class="toggle-button" @click="isCollapse = ! isCollapse">|||</div>
        <!-- 左侧菜单区域 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409bff"
          unique-opened 
          :collapse="isCollapse"
          :collapse-transition="false"
          router
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="item.id + ''"
            :key="item.id"
            v-for="item in menulist"
          >
            <template slot="title">
              <i :class="iconlist[item.id]"></i>
              <span class="listMenuName">{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/' + subItem.path"
              :key="subItem.id"
              v-for="subItem in item.children"
              @click="saveNavPath('/'+subItem.path)"
            >
              <template slot="title">
                <i :class="iconlist1[subItem.id]"></i>
                <span class="listMenuName">{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
        <div class="copy-right" v-show="!isCollapse">Powered by <span>恰饭啦团队</span></div>
      </el-aside>
      <!-- 主体内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // 头部动画
      showLogo: false,
      showName: false,
      // 菜单列表
      // 激活的链接
      activePath: "",
      isCollapse: false,
      // 左侧菜单列表
      menulist: [
        {
          id: 100,
          authName: "订单管理",
          children: [
            {
              id: 101,
              authName: "正处理",
              path: "ordering"
            },
            {
              id: 102,
              authName: "已完成",
              path: "ordered"
            }
          ]
        },
        {
          id: 200,
          authName: "库存管理",
          children: [
            {
              id: 201,
              authName: "库存列表",
              path: "stocklist"
            }
          ]
        },
        {
          id: 300,
          authName: "菜单管理",
          children: [
            {
              id: 3011,
              authName: "分类列表",
              path: "menucates"
            },
            {
              id: 301,
              authName: "菜单列表",
              path: "menulist"
            },
            {
              id: 302,
              authName: "新增菜单",
              path: "menuadd"
            }
          ]
        },
        {
          id: 400,
          authName: "评论管理",
          children: [
            {
              id: 401,
              authName: "评论列表",
              path: "commentlist"
            }
          ]
        }
      ],
      // 图标列表
      // 一级菜单
      iconlist: {
        '100': 'iconfont icon-icon-',
        '200': 'iconfont icon-_kucun',
        '300': 'iconfont icon-caidan1',
        '400': 'iconfont icon-comment-copy'
      },
      // 二级菜单
      iconlist1: {
        '101': 'iconfont icon-zhengzaibanlifuwudan',
        '102': 'el-icon el-icon-check',
        '201': 'iconfont icon-biaodanliebiao-',
        '3011': 'iconfont icon-biaodanliebiao-',
        '301': 'iconfont icon-caidan',
        '302': 'iconfont icon-zengjiaxinzeng',
        '401': 'iconfont icon-pinglun'
      },
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  mounted() {
    //   头部动画
    setTimeout(() => {
      this.showLogo = true
      this.showName = true
    }, 200)
  },
  methods: {
    //点击退出登录
    logout() {
      //清除localStorage
      window.localStorage.clear();
      window.sessionStorage.clear()
      this.$router.push("/")
    },
    //点击保存链接到session
    saveNavPath(activePath) {
      window.sessionStorage.setItem('activePath',activePath)
      this.activePath = activePath
    }
  }
}
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
  //   头部区域
  .el-header {
    background-color: rgb(28, 132, 231);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 23px;
    padding: 0;
    span {
      color: #fff;
    }
    .logo {
      font-size: 29px;
    }
    .transition-box1 {
      width: 250px;
      text-align: center;
    }
    .transition-box2 {
      position: absolute;
      left: 40%;
      transform: translateX(30%);
    }
    .logout {
      position: absolute;
      right: 20px;
      color: #909399;
    }
  }
  //   侧边栏
  .el-aside {
    height: 100%;
    background-color: #333744;
    position: relative;
    user-select: none;
    .el-menu {
      width: 100%;
      border-right: 0;
    }
    .el-submenu{
      color: #fff;
    }
    .toggle-button {
        font-size: 10px;
        line-height: 30px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
        user-select: none;
      }
      .listMenuName {
        margin-left: 10px;
      }
      .el-submenu {
        width: 100%;
        i {
          font-size: 20px;
        }
        .el-menu-item {
          font-size: 14px;
        }
      }
      .el-submenu__title {
        width: 100%;
      }
    .copy-right {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 36px;
      background: #2d3436;
      color: #fff;
      font-size: 13px;
      line-height: 36px;
      text-align: center;
      > span {
        color: rgb(28, 132, 231);
      }
    }
  }
  //   主体内容
  .el-main {
    background-color: #eaedf1;
  }
}
</style>
